<?php

class GantiKartuController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	//public $layout='//layouts/column2';

	/**
	 * @return array action filters
	 */

	/*
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete', // we only allow deletion via POST request
		);
	}
	*/

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	/*
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','update','cetak','generateExcel'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	*/


	public function actionGenerateExcel()
	{
            $session=new CHttpSession;
            $session->open();		
            
             if(isset($session['NdkHealth_records']))
               {
                $model=$session['NdkHealth_records'];
               }
               else
                 $model = NdkHealth::model()->findAll();

		
		Yii::app()->request->sendFile(date('YmdHis').'.xls',
			$this->renderPartial('excelReport', array(
				'model'=>$model
			), true)
		);
	}


	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{

		$this->render('view',array(
			'model'=>$this->loadModel($id),
		));
	}


	public function actionPosting($id)
	{	
	$this->render('posting',array(
			'model'=>$this->loadModel($id),
		));	
	}


	public function actionProsesPosting($id)
	{	
		$model=$this->loadModel($id);
		
		$sql = 'update ganti_kartu set posting=2 where id='.$id;
		Yii::app()->db->createCommand($sql)->queryAll();
		

		$this->render('prosesPosting',array(
			'model'=>$model,
		));
		
	}


	public function actionCetak()
	{
		//if (isset($_POST['NdkHealth'])) {
			//$reg_health_policy_id = $_REQUEST['reg_health_policy_id'];
			//$master_id = $_REQUEST['master_id'];
			$id = $_REQUEST['id'];
			$paramsInput = array("id"=>(int)$id);
			Yii::app()->printUtils->executeReport($paramsInput,'gantiKartu/notadebet.jrxml','gantiKartu','gantiKartu');
		//}

		//$this->render('cetak');
	}

	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	
	public function actionCreate()
	{
		$model=new NdkHealth('search');
		$model2=new MstClient('searchModal');
		$modelKartu=new GantiKartu('search');
		$model2->unsetAttributes();  // clear any default values
		if (isset($_GET['MstClient'])) {
			$model2->attributes=$_GET['MstClient'];
		}

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
		$temp_id = date("Ymdhis");

		if (isset($_POST['GantiKartu'])) {
			$nota_no = 'NP'.$temp_id;
			//--  Untuk Ndk Health Master --//
			
			
			//--  Untuk Ndk Health Master --//
			$modelKartu->nota_no = $nota_no;
			$modelKartu->endorsement_no = trim($_POST['GantiKartu']['endorsement_no']);
			
				$modelKartu->admin_broker = trim($_POST['GantiKartu']['admin_broker']);
				$modelKartu->stamp_duty = trim($_POST['GantiKartu']['stamp_duty']);
				$modelKartu->stampduty_asuransi = trim($_POST['GantiKartu']['stampduty_asuransi']);
				$modelKartu->discount = (int)trim($_POST['GantiKartu']['discount']);
				$modelKartu->diskon_asuransi = (int)trim($_POST['GantiKartu']['diskon_asuransi']);
				$modelKartu->due_date = date('Y-m-d',strtotime($_POST['GantiKartu']['due_date']));

				$modelKartu->posting = 1;
				$modelKartu->type_reg_policy = trim($_POST['GantiKartu']['type_reg_policy']);
				$modelKartu->reg_policy_id = trim($_POST['GantiKartu']['reg_policy_id']);
				$modelKartu->note = trim($_POST['GantiKartu']['note']);
				$modelKartu->createdby = Yii::app()->user->getId();
				$modelKartu->createdtime = date('Y-m-d H:i:s');
				$modelKartu->updatedby = Yii::app()->user->getId();
				$modelKartu->updatedtime = date('Y-m-d H:i:s');
				
			
				$modelKartu->biaya_kartu = (int)trim($_POST['GantiKartu']['biaya_kartu']);
				$modelKartu->value_brokerage = (int)trim($_POST['GantiKartu']['value_brokerage']);

				
				
				$modelKartu->nominal = (int)trim($_POST['GantiKartu']['biaya_kartu'])+(int)trim($_POST['GantiKartu']['admin_broker'])+(int)trim($_POST['GantiKartu']['stamp_duty'])+(int)trim($_POST['GantiKartu']['stampduty_asuransi'])-(int)trim($_POST['GantiKartu']['discount'])-(int)trim($_POST['GantiKartu']['diskon_asuransi']);		
				
				
				$modelKartu->nett_to_insurance = (int)trim($_POST['GantiKartu']['biaya_kartu'])-(int)trim($_POST['GantiKartu']['diskon_asuransi'])+(int)trim($_POST['GantiKartu']['stampduty_asuransi']);

				$modelKartu->save();

			//--  Untuk Ndk Health Master --//

		
				$this->redirect(array('admin'));
				
			
		}

		$this->render('create',array(
			'model'=>$model,
			'model2'=>$model2,
			'modelKartu'=>$modelKartu,
		));
	}

	

	/**
	 * Updates a particular model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param integer $id the ID of the model to be updated
	 */
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);
		$model2=new MstClient('searchModal');
		$model3=new RegHealthPolicy('search');
		$model2->unsetAttributes();  // clear any default values
		if (isset($_GET['MstClient'])) {
			$model2->attributes=$_GET['MstClient'];
		}

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
		$temp_id = date("Ymdhis");

		if (isset($_POST['NdkHealthMaster'])) {
			
			//--  Untuk Ndk Health Master --//

			NdkHealthMaster::model()->deleteAll('id='.$id);
			NdkHealth::model()->deleteAll('ndk_health_master_id='.$id);

			$modelNdkHealthMaster = new NdkHealthMaster;

			//--  Untuk Ndk Health Master --//
			$modelNdkHealthMaster->nota_debet_no = '0';
			$modelNdkHealthMaster->reg_health_policy_id = trim($_POST['NdkHealthMaster']['reg_health_policy_id']);

			$modelNdkHealthMaster->endorsement_no = trim($_POST['NdkHealthMaster']['endorsement_no']);
			$modelNdkHealthMaster->sisa_bayar = 0;
			$modelNdkHealthMaster->kurang_bayar = 0;
			$modelNdkHealthMaster->jml_bayar = 0;
			$modelNdkHealthMaster->is_bayar = '0';
			$modelNdkHealthMaster->client_tahu_diskon = trim($_POST['NdkHealthMaster']['client_tahu_diskon']);
		
				$modelNdkHealthMaster->admin_broker = trim($_POST['NdkHealthMaster']['admin_broker']);
				$modelNdkHealthMaster->discount = (int)trim($_POST['NdkHealthMaster']['discount']);
				$modelNdkHealthMaster->discount_percent = trim($_POST['NdkHealthMaster']['discount_percent']);
				$modelNdkHealthMaster->adjusment = trim($_POST['NdkHealthMaster']['adjusment']);
				$modelNdkHealthMaster->due_date = trim($_POST['NdkHealthMaster']['due_date']);
				$modelNdkHealthMaster->brokerage = (int)trim($_POST['NdkHealthMaster']['brokerage']);
				$modelNdkHealthMaster->brokerage_percent = trim($_POST['NdkHealthMaster']['brokerage_percent']);
				$modelNdkHealthMaster->ppn = (int)trim($_POST['NdkHealthMaster']['ppn']);
				$modelNdkHealthMaster->ppn_percent = trim($_POST['NdkHealthMaster']['ppn_percent']);
				$modelNdkHealthMaster->pph = (int)trim($_POST['NdkHealthMaster']['pph']);
				$modelNdkHealthMaster->pph_percent = trim($_POST['NdkHealthMaster']['pph_percent']);
				$modelNdkHealthMaster->note = trim($_POST['NdkHealthMaster']['note']);
				$modelNdkHealthMaster->createdby = Yii::app()->user->getId();
				$modelNdkHealthMaster->createdtime = date('Y-m-d H:i:s');
				$modelNdkHealthMaster->updatedby = Yii::app()->user->getId();
				$modelNdkHealthMaster->updatedtime = date('Y-m-d H:i:s');
				$modelNdkHealthMaster->installment_ke = 0;
				$modelNdkHealthMaster->stamp_duty = trim($_POST['NdkHealthMaster']['stamp_duty']);
				$modelNdkHealthMaster->stampduty_asuransi = trim($_POST['NdkHealthMaster']['stampduty_asuransi']);
				$modelNdkHealthMaster->policy_cost = trim($_POST['NdkHealthMaster']['policy_cost']);
				$modelNdkHealthMaster->premium = (int)trim($_POST['NdkHealthMaster']['premium']);
				$modelNdkHealthMaster->diskon_asuransi = (int)trim($_POST['NdkHealthMaster']['diskon_asuransi']);
				$modelNdkHealthMaster->diskon_asuransi_percent = trim($_POST['NdkHealthMaster']['diskon_asuransi_percent']);			
				$modelNdkHealthMaster->client_tahu_diskon = trim($_POST['NdkHealthMaster']['client_tahu_diskon']);
				$modelNdkHealthMaster->posting = 1;
				$modelNdkHealthMaster->type = trim($_POST['NdkHealthMaster']['type']);
				$modelNdkHealthMaster->value_brokerage = (int)trim($_POST['NdkHealthMaster']['value_brokerage']);

				//if((int)$_POST['NdkHealthMaster']['diskon_asuransi']==1){
				if((int)$_POST['NdkHealthMaster']['client_tahu_diskon']==1){
				$modelNdkHealthMaster->nominal = (int)trim($_POST['NdkHealthMaster']['premium'])+(int)trim($_POST['NdkHealthMaster']['adjusment'])+(int)trim($_POST['NdkHealthMaster']['policy_cost'])+(int)trim($_POST['NdkHealthMaster']['stamp_duty'])+(int)trim($_POST['NdkHealthMaster']['stampduty_asuransi'])+(int)trim($_POST['NdkHealthMaster']['admin_broker'])-(int)trim($_POST['NdkHealthMaster']['discount']);	
				}
				else{
				$modelNdkHealthMaster->nominal = (int)trim($_POST['NdkHealthMaster']['premium'])+(int)trim($_POST['NdkHealthMaster']['adjusment'])+(int)trim($_POST['NdkHealthMaster']['policy_cost'])+(int)trim($_POST['NdkHealthMaster']['stamp_duty'])+(int)trim($_POST['NdkHealthMaster']['stampduty_asuransi'])+(int)trim($_POST['NdkHealthMaster']['admin_broker'])-(int)trim($_POST['NdkHealthMaster']['discount'])-(int)trim($_POST['NdkHealthMaster']['diskon_asuransi']);		
				}
				
				$modelNdkHealthMaster->nett_to_insurance = (int)trim($_POST['NdkHealthMaster']['premium'])-(int)trim($_POST['NdkHealthMaster']['diskon_asuransi'])+(int)trim($_POST['NdkHealthMaster']['policy_cost'])+(int)trim($_POST['NdkHealthMaster']['stampduty_asuransi'])-(int)trim($_POST['NdkHealthMaster']['brokerage'])-(int)trim($_POST['NdkHealthMaster']['ppn'])+(int)trim($_POST['NdkHealthMaster']['pph']);
				echo $modelNdkHealthMaster->nett_to_insurance;
				$modelNdkHealthMaster->save();

			//--  Untuk Ndk Health Master --//



			$due_date = explode('|',$_POST['NdkHealthMaster']['due_date']);

			for($i=0;$i<count($due_date);$i++){
				$no = (int)$i+1;
				$modelNew = new NdkHealth;
				$nota_debet_no = 'HG'.$temp_id.'D2.0'.$no;	

				$modelNew->ndk_health_master_id = $modelNdkHealthMaster->id;
				$modelNew->nota_debet_no = $nota_debet_no;
				$modelNew->reg_health_policy_id = trim($_POST['NdkHealthMaster']['reg_health_policy_id']);
				$modelNew->endorsement_no = trim($_POST['NdkHealthMaster']['endorsement_no']);
				$modelNew->sisa_bayar = 0;
				$modelNew->kurang_bayar = 0;
				$modelNew->jml_bayar = 0;
				$modelNew->is_bayar = '0';
				$modelNew->client_tahu_diskon = trim($_POST['NdkHealthMaster']['client_tahu_diskon']);

				if($i==0){
					$policy_cost = trim($_POST['NdkHealthMaster']['policy_cost']);
					$stamp_duty = trim($_POST['NdkHealthMaster']['stamp_duty']);
					$stampduty_asuransi = trim($_POST['NdkHealthMaster']['stampduty_asuransi']);
					$admin_broker = trim($_POST['NdkHealthMaster']['admin_broker']);
					$discount_percent = trim($_POST['NdkHealthMaster']['discount_percent']);
					$diskon_asuransi_percent = trim($_POST['NdkHealthMaster']['diskon_asuransi_percent']);
					$adjusment = trim($_POST['NdkHealthMaster']['adjusment']);

				}
				else{
					$policy_cost = 0;
					$stamp_duty = 0;
					$admin_broker = 0;
					$discount = 0;
					$discount_percent = 0;
					$stampduty_asuransi = 0;
					$diskon_asuransi = 0;
					$diskon_asuransi_percent = 0;
					$adjusment = 0;
				}
					$discount = (int)trim($_POST['NdkHealthMaster']['discount'])/count($due_date);
					$diskon_asuransi = $_POST['NdkHealthMaster']['diskon_asuransi']/count($due_date);
										
					$brokerage = (int)trim($_POST['NdkHealthMaster']['brokerage'])/count($due_date);
					$brokerage_percent = trim($_POST['NdkHealthMaster']['brokerage_percent']);
					$ppn = (int)trim($_POST['NdkHealthMaster']['ppn'])/count($due_date);
					$ppn_percent = trim($_POST['NdkHealthMaster']['ppn_percent']);
					$pph = (int)trim($_POST['NdkHealthMaster']['pph'])/count($due_date);
					$pph_percent = trim($_POST['NdkHealthMaster']['pph_percent']);

				$modelNew->endorsement_no = trim($_POST['NdkHealthMaster']['endorsement_no']);
				
				if($client_tahu_diskon==1){
				$modelNew->nominal = (((int)trim($_POST['NdkHealthMaster']['premium']))/count($due_date))+(int)$adjusment+(int)$policy_cost+(int)$stamp_duty+(int)$stampduty_asuransi+(int)$admin_broker-(int)$discount;	
				}
				else{
				$modelNew->nominal = (((int)trim($_POST['NdkHealthMaster']['premium']))/count($due_date))+(int)$adjusment+(int)$policy_cost+(int)$stamp_duty+(int)$stampduty_asuransi+(int)$admin_broker-(int)$discount-(int)$diskon_asuransi;
				}
				
				$modelNew->nett_to_insurance = (((int)trim($_POST['NdkHealthMaster']['premium']))/count($due_date))-(int)$diskon_asuransi+(int)$policy_cost+(int)$stampduty_asuransi-(int)$brokerage-(int)$ppn+(int)$pph;
				
				$modelNew->admin_broker = $admin_broker;
				$modelNew->discount = $discount;
				$modelNew->discount_percent = $discount_percent;
				$modelNew->adjusment = $adjusment;
				$modelNew->due_date = date('Y-m-d',strtotime($due_date[$i]));
				$modelNew->brokerage = $brokerage;
				$modelNew->brokerage_percent = $brokerage_percent;
				$modelNew->ppn = $ppn;
				$modelNew->ppn_percent = $ppn_percent;
				$modelNew->pph = $pph;
				$modelNew->pph_percent = $pph_percent;
				$modelNew->note = trim($_POST['NdkHealthMaster']['note']);
				$modelNew->createdby = Yii::app()->user->getId();
				$modelNew->createdtime = date('Y-m-d H:i:s');
				$modelNew->updatedby = Yii::app()->user->getId();
				$modelNew->updatedtime = date('Y-m-d H:i:s');
				$modelNew->installment_ke = $i+1;
				$modelNew->stamp_duty = $stamp_duty;
				$modelNew->stampduty_asuransi = $stampduty_asuransi;
				$modelNew->policy_cost = $policy_cost;
				$modelNew->premium = ((int)trim($_POST['NdkHealthMaster']['premium']))/count($due_date);
				$modelNew->diskon_asuransi = $diskon_asuransi;
				$modelNew->diskon_asuransi_percent = $diskon_asuransi_percent;			
				$modelNew->client_tahu_diskon = (int)trim($_POST['NdkHealthMaster']['client_tahu_diskon']);
				$modelNew->posting = 1;
				$modelNew->type = trim($_POST['NdkHealthMaster']['type']);
				$modelNew->value_brokerage = (int)trim($_POST['NdkHealthMaster']['value_brokerage']);
				$modelNew->save();
			}
			
				$this->redirect(array('admin'));
			
		}

		$this->render('update',array(
			'model'=>$model,
			'model2'=>$model2,
			'model3'=>$model3,
		));
	}

	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		if (Yii::app()->request->isPostRequest) {
			// we only allow deletion via POST request
			$this->loadModel($id)->delete();

			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if (!isset($_GET['ajax'])) {
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
			}
		} else {
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
		}
	}

	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
		$dataProvider=new CActiveDataProvider('NdkHealth');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new GantiKartu('search');
		$model->unsetAttributes();  // clear any default values
		if (isset($_GET['GantiKartu'])) {
			$model->attributes=$_GET['GantiKartu'];
		}

		$this->render('admin',array(
			'model'=>$model,
		));
		
		
	}

	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer $id the ID of the model to be loaded
	 * @return NdkHealth the loaded model
	 * @throws CHttpException
	 */
	public function loadModel($id)
	{
		$model=GantiKartu::model()->findByPk($id);
		if ($model===null) {
			throw new CHttpException(404,'The requested page does not exist.');
		}
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param NdkHealth $model the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if (isset($_POST['ajax']) && $_POST['ajax']==='ndk-health-form') {
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}



		public function actionExport(){

	  $nama_file = $_POST['nama_file'];	
	  $start = $_POST['start'];
	  Yii::import('ext.phpexcel.XPHPExcel');    
	  $objPHPExcel= XPHPExcel::createPHPExcel();
	  $objPHPExcel->getProperties()->setCreator("")
                             ->setLastModifiedBy("")
                             ->setTitle("")
                             ->setSubject("")
                             ->setDescription("")
                             ->setKeywords("")
                             ->setCategory("");

$objPHPExcel->getDefaultStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

 




/*
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('C1', 'Kode Pemda')
            ->setCellValue('C2', 'Jumlah Data')
            ->setCellValue('C3', 'Tagihan')
            ->setCellValue('C4', 'Denda')
            ->setCellValue('C5', 'Total');

$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('D1', $cmdProp[0]['kd_dati2'])
            ->setCellValue('D2', '10000')
            ->setCellValue('D3', $cmdTagihan[0]['hasil'])
            ->setCellValue('D4', $cmdDenda[0]['hasil'])
            ->setCellValue('D5', $cmdTotal[0]['hasil']);

*/



// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('ExportPBB');



$objPHPExcel->getActiveSheet()->SetCellValue('B'.$j, $i+1);
$objPHPExcel->getActiveSheet()->SetCellValue('C'.$j, $cmdExport[$i]['nop']);
$objPHPExcel->getActiveSheet()->SetCellValue('D'.$j, $cmdExport[$i]['fiscal_year']);
$objPHPExcel->getActiveSheet()->SetCellValue('E'.$j, $cmdExport[$i]['fullname']);
$objPHPExcel->getActiveSheet()->SetCellValue('F'.$j, $cmdExport[$i]['address_wp']);
$objPHPExcel->getActiveSheet()->SetCellValue('G'.$j, '');
$objPHPExcel->getActiveSheet()->SetCellValue('H'.$j, substr($cmdExport[$i]['nop'], 0,2));
$objPHPExcel->getActiveSheet()->SetCellValue('I'.$j, substr($cmdExport[$i]['nop'], 2,2));
$objPHPExcel->getActiveSheet()->SetCellValue('J'.$j, substr($cmdExport[$i]['nop'], 4,2));
$objPHPExcel->getActiveSheet()->SetCellValue('K'.$j, substr($cmdExport[$i]['nop'], 6,2));
$objPHPExcel->getActiveSheet()->SetCellValue('L'.$j, $cmdExport[$i]['rt_op']);
$objPHPExcel->getActiveSheet()->SetCellValue('M'.$j, $cmdExport[$i]['rw_op']);
$objPHPExcel->getActiveSheet()->SetCellValue('N'.$j, $cmdExport[$i]['land_area']);
$objPHPExcel->getActiveSheet()->SetCellValue('O'.$j, $cmdExport[$i]['building_area']);
$objPHPExcel->getActiveSheet()->SetCellValue('P'.$j, date('m/d/Y',strtotime($cmdExport[$i]['payment_due_date'])));
$objPHPExcel->getActiveSheet()->SetCellValue('Q'.$j, $cmdExport[$i]['fine']);
$objPHPExcel->getActiveSheet()->SetCellValue('R'.$j, $cmdExport[$i]['amount']);
$objPHPExcel->getActiveSheet()->SetCellValue('S'.$j, $cmdExport[$i]['total']);


$objPHPExcel->setActiveSheetIndex(0);

 

// Redirect output to a clientâ€™s web browser (Excel5)
//header('Content-Type: application/vnd.ms-excel');
//header('Content-Disposition: attachment;filename="'.$nama_file.'.xls"');
//header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content-Disposition: attachment;filename="'.$nama_file.'"');

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header('Content-Disposition: attachment;filename="'.$nama_file.'.xls"');
header("Content-Transfer-Encoding: binary ");

 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2003XML');
//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
Yii::app()->end();

}


public function actionExportCoy(){
		$objPHPExcel=Yii::createComponent('application.extensions.PHPExcel');
        $objPHPExcel->setActiveSheetIndex(0)
                    ->setCellValue('A1', 'Ini di A No 1 ya')
                    ->setCellValue('B2', 'kalau ini B 2')
                    ->setCellValue('C1', 'Ini di C1')
                    ->setCellValue('D2', 'Terakhir di D 2');
        // Redirect output to a client’s web browser (Excel2007)

        // Load the table view into a variable
		//$html = $this->load->view('table_view', $data, true);

        $html = $this->renderPartial('excelReport');
        

		$text='<table border="1" style="border:1px;">

		<tr>
		<th width="80px">
		      id		</th>
 		<th width="80px">
		      No Nota Debet		</th>
 		<th width="80px">
		      No Polis		</th>
 		<th width="80px">
		      No Endors		</th>
 		<th width="80px">
		      nominal		</th>
 		<th width="80px">
		      policy_cost		</th>
 	</tr></table>';       	
		// Put the html into a temporary file
		$tmpfile = 'D:\testexport.html';
		file_put_contents($tmpfile, $text);

		// Read the contents of the file into PHPExcel Reader class
		$reader = new PHPExcel_Reader_HTML; 
		$content = $reader->load($tmpfile); 
		// Delete temporary file
		//unlink($tmpfile);
		            

        $objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
        $objWriter->save('php://output');
        unset($objPHPExcel);

        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="contoh01.xlsx"');
        header('Cache-Control: max-age=0');
        // If you're serving to IE 9, then the following may be needed
        header('Cache-Control: max-age=1');

        // If you're serving to IE over SSL, then the following may be needed
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        
}


}